<?php

namespace addons\cms\model;

use think\Model;

class Societies extends Model
{
    // 表名
    protected $name = 'cms_societies';


    /**
     * 生成随机数
     * @param int $length
     * @return string
     */
    public function memberCode($length)
    {
        $pattern = array ( '1', '2', '3', '4', '5', '6', '7', '8', '9', '0');
        $key = '';
        for ($i = 0; $i < $length; $i++) {
            $key .= array_rand($pattern); // 生成php随机数
        }
        if (User::where('societies_no',$key)->find()) {
            return $this->memberCode($length);
        }
        return $key;
    }
}
